package com.kc.web.controller.business;

import com.kc.business.domain.BizScenicCultural;
import com.kc.business.service.IBizScenicCulturalService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/9/24
 */
@RestController
@RequestMapping("/business/scenicCultural")
public class BizScenicCulturalContorller extends BaseController {
    @Autowired
    private IBizScenicCulturalService scenicCulturalService;

    /**
     * 获取景区文创列表
     */
    @PreAuthorize("@ss.hasPermi('business:scenicCultural:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizScenicCultural scenicCultural) {
        startPage();
        List<BizScenicCultural> list = scenicCulturalService.getList(scenicCultural);
        return getDataTable(list);
    }

    /**
     * 新增景区文创
     */
    @PreAuthorize("@ss.hasPermi('business:scenicCultural:add')")
    @Log(title = "景区文创管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizScenicCultural scenicCultural) {
        BizScenicCultural _scenicCultural1 = new BizScenicCultural();
        _scenicCultural1.setScenicId(scenicCultural.getScenicId());
        if (scenicCulturalService.getList(_scenicCultural1).size() > 0) {
            return AjaxResult.error("同一景区不可重复征集");
        }
        return toAjax(scenicCulturalService.add(scenicCultural));
    }

    /**
     * 修改景区文创
     */
    @PreAuthorize("@ss.hasPermi('business:scenicCultural:edit')")
    @Log(title = "景区文创管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizScenicCultural scenicCultural) {
        return toAjax(scenicCulturalService.edit(scenicCultural));
    }
}
